/*
 * Created by Wang Lei on 21-07-01.
 * Copyright (c) 2006-2021 Kaitiren
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace HLLib
{
    /// <summary>
    /// HLUtil
    /// </summary>
    public class HLUtil
    {
		public static bool IS_RELEASE = false;

		/// <summary>
		/// Debugs the print.
		/// </summary>
		/// <param name="message">Message.</param>
		public static void Log(string _message)
		{
			if (!IS_RELEASE)
				Debug.Log(_message);
		}


		/// <summary>
		/// Debugs the println.
		/// </summary>
		public static void Logn(string _tag, string _message)
		{
			if (!IS_RELEASE)
				Debug.Log(_tag + "\n" + _message);
		}


		/// <summary>
		/// Debugs the draw point.
		/// </summary>
		/// <param name="sx">Sx.</param>
		/// <param name="sy">Sy.</param>
		/// <param name="_color">_color.</param>
		public static void debugDrawPoint2d(float sx, float sy, Color _color)
		{
			Debug.DrawLine(new Vector3(sx, 0.0f, sy), new Vector3(sx + 0.01f, 0.0f, sy + 0.01f), _color);
		}



		/// <summary>
		/// Debugs the draw line.
		/// </summary>
		/// <param name="sx">Sx.</param>
		/// <param name="sy">Sy.</param>
		/// <param name="ax">Ax.</param>
		/// <param name="ay">Ay.</param>
		/// <param name="_color">_color.</param>
		public static void debugDrawLine2d(float sx, float sy, float ax, float ay, Color _color)
		{
			if (sx == ax || sy == ay)
				return;
			Debug.DrawLine(new Vector3(sx, 0.0f, sy), new Vector3(ax, 0.0f, ay), _color);
		}


		/// <summary>
		/// Debugs the draw rect2d.
		/// </summary>
		/// <param name="sx">Sx.</param>
		/// <param name="sy">Sy.</param>
		/// <param name="sw">Sw.</param>
		/// <param name="sh">Sh.</param>
		/// <param name="_color">_color.</param>
		public static void debugDrawRect2d(float sx, float sy, float sw, float sh, Color _color)
		{
			Vector3 vec_lb = new Vector3(sx, 0.0f, sy);
			Vector3 vec_rb = new Vector3(sx + sw, 0.0f, sy);
			Vector3 vec_lt = new Vector3(sx, 0.0f, sy + sh);
			Vector3 vec_rt = new Vector3(sx + sw, 0.0f, sy + sh);
			Debug.DrawLine(vec_lb, vec_rb, _color);
			Debug.DrawLine(vec_rb, vec_rt, _color);
			Debug.DrawLine(vec_rt, vec_lt, _color);
			Debug.DrawLine(vec_lt, vec_lb, _color);
			///
		}


		/// <summary>
		/// Debugs the draw arc2d.
		/// </summary>
		/// <param name="sx">Sx.</param>
		/// <param name="sy">Sy.</param>
		/// <param name="r">The red component.</param>
		/// <param name="_color">_color.</param>
		public static void debugDrawArc2d(float sx, float sy, float r, Color _color)
		{
			for (int i = 0; i < 360; i++)
			{
				float x_arc = Mathf.Sin(Mathf.Deg2Rad * i) * r + sx;
				float y_arc = Mathf.Cos(Mathf.Deg2Rad * i) * r + sy;
				debugDrawPoint2d(x_arc, y_arc, _color);
			}
		}


		/// <summary>
		/// Debugs the draw polygon.(3 point)
		/// </summary>
		public static void debugDrawTriangle2d(Vector3[] vec3_array, Color _color)
		{
			if (null == vec3_array && vec3_array.Length != 3)
				return;
			Vector3 vec_a = vec3_array[0];
			Vector3 vec_b = vec3_array[1];
			Vector3 vec_c = vec3_array[2];
			Debug.DrawLine(vec_a, vec_b, _color);
			Debug.DrawLine(vec_b, vec_c, _color);
			Debug.DrawLine(vec_c, vec_a, _color);
		}

	}
}
